import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:trtc_demo/page/live/index.dart';
import 'package:trtc_demo/page/live/live_pusher.dart';
import 'package:trtc_demo/page/live/live_video.dart';
import 'package:trtc_demo/page/trtcmeetingdemo/index.dart';
import 'package:trtc_demo/page/trtcmeetingdemo/meeting.dart';
import 'package:trtc_demo/page/trtcmeetingdemo/member_list.dart';
import 'package:trtc_demo/page/trtcmeetingdemo/test_api.dart';
import 'package:trtc_demo/models/meeting.dart';
import 'package:tencent_trtc_cloud/live/rtmp_tencent_live.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]).then((_) {
    runApp(MyApp());
    TencentLive.instance.init(
        licenseUrl: 'http://license.vod2.myqcloud.com/license/v1/dff72afd7ed107ea5ee74500289713b2/TXLiveSDK.licence',
        licenseKey: '4ce6f0e4c42031e285f192fb656576f4'
    );
  });
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (context) => MeetingModel(),
      child: MaterialApp(
        home: HomeNavigate(),
        routes: {
          "/trtc": (context) => IndexPage(),
          "/index": (context) => IndexPage(),
          "/video": (context) => MeetingPage(),
          "/memberList": (context) => MemberListPage(),
          "/test": (context) => TestPage(),
          "/live":(context) => LiveIndex(),
          '/livePusher': (BuildContext context) => LivePusher(),
          '/liveVideo': (BuildContext context) => LiveVideo(),
        },
      ),
    );
  }
}

class HomeNavigate extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("导航"),
      ),
      body: Container(
        child: ListView(
          children: [
            ListTile(
              title: Text('实时音视频'),
              trailing: Icon(Icons.arrow_right),
              onTap: () => Navigator.pushNamed(context, '/trtc'),
            ),
            ListTile(
              title: Text('直播'),
              trailing: Icon(Icons.arrow_right),
              onTap: () => Navigator.pushNamed(context, '/live'),
            ),
          ],
        ),
      ),
    );
  }
}

